package com.wanxi.repertory.service.core_service.impl;

import com.wanxi.repertory.service.api.dto.EnterpriseRepertoryDto;
import com.wanxi.repertory.service.api.dto.ShopRepertoryDto;
import com.wanxi.repertory.service.api.entity.EnterpriseRepertory;
import com.wanxi.repertory.service.api.entity.ShopRepertory;
import com.wanxi.repertory.service.mapper.EnterpriseRepertoryMapper;
import com.wanxi.repertory.service.mapper.ShopRepertoryMapper;
import com.wanxi.repertory.service.core_service.RepertoryTotalService;
import com.wanxi.repertory.service.utill.BeanCopyUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RepertoryTotalServiceImpl implements RepertoryTotalService {
    @Resource
    ShopRepertoryMapper shopRepertoryMapper;

    @Override
    public Long addShopRepertory(ShopRepertoryDto shopRepertoryDto) {
        ShopRepertory shopRepertory = BeanCopyUtils.copy(shopRepertoryDto,ShopRepertory.class);
        shopRepertoryMapper.add(shopRepertory);
        return shopRepertory.getSkuId();
    }

    @Override
    public ShopRepertoryDto findShopRepertoryBySkuId(Long skuId) {
        ShopRepertory shopRepertory = shopRepertoryMapper.findShopRepertoryBySkuId(skuId);
        return BeanCopyUtils.copy(shopRepertory,ShopRepertoryDto.class);
    }

    @Override
    public List<Long> findSkuIdByShopId(Long shopId) {
        return shopRepertoryMapper.findSkuIdByShopId(shopId);
    }

    @Override
    public Long findShopIdBySkuId(Long skuId) {
        return shopRepertoryMapper.findShopIdBySkuId(skuId);
    }

    @Override
    public int updateShopRepertory(ShopRepertoryDto shopRepertoryDto) {
        ShopRepertory shopRepertory = BeanCopyUtils.copy(shopRepertoryDto,ShopRepertory.class);
        return shopRepertoryMapper.update(shopRepertory);
    }

    @Resource
    EnterpriseRepertoryMapper enterpriseRepertoryMapper;

    @Override
    public Long addEnterpriseRepertory(EnterpriseRepertoryDto enterpriseRepertoryDto) {
        EnterpriseRepertory enterpriseRepertory = BeanCopyUtils.copy(enterpriseRepertoryDto,EnterpriseRepertory.class);
        enterpriseRepertoryMapper.add(enterpriseRepertory);
        return enterpriseRepertory.getSkuId();
    }

    @Override
    public EnterpriseRepertoryDto findEnterpriseRepertoryBySkuId(Long skuId) {
        EnterpriseRepertory enterpriseRepertory = enterpriseRepertoryMapper.findBySkuId(skuId);
        return BeanCopyUtils.copy(enterpriseRepertory,EnterpriseRepertoryDto.class);
    }

    @Override
    public List<Long> findSkuIdByEnterpriseId(Long enterpriseId) {
        return enterpriseRepertoryMapper.findSkuIdByEnterpriseId(enterpriseId);
    }

    @Override
    public int updateEnterpriseRepertory(EnterpriseRepertoryDto enterpriseRepertoryDto) {
        EnterpriseRepertory enterpriseRepertory = BeanCopyUtils.copy(enterpriseRepertoryDto,EnterpriseRepertory.class);
        return enterpriseRepertoryMapper.update(enterpriseRepertory);
    }

}
